import Vue from 'vue'
import VueRouter from 'vue-router'
import show from '../views/epai_show'
import detail from '../views/epai_product_detail'
import Sale from '../views/Sale'
import index from '../views/Index'
import product from '../views/epai_product'
import epai_vip from '../views/epai_vip.vue'
import myvip from '../views/e_myvip.vue'
import vips from '../views/e_vip.vue'
import idnum from '../views/epai_vip_register.vue'
import pai from '../views/epai_pai.vue'
import this_pai from '../views/epai_this_pai.vue'
import login from '../views/e_login.vue'
import register from '../views/e_register.vue'
import myvip_leave from '../views/e_myvip_leave.vue'
import money from '../views/e_money.vue'
//订单主组件
import Order from '../views/Order.vue'
//全部订单组件
import AllOrder from '../views/AllOrder.vue'
//已支付订单组件
import SuccessFulOrder from '../views/SuccessFulOrder.vue'
//未支付订单组件
import UnpaidOrder from '../views/UnpaidOrder.vue'
//支付失败订单组件
import FailedOrder from '../views/FailedOrder.vue'


Vue.use(VueRouter)

const routes = [{
        path: '/',
        name: 'index',
        component: index,
    }, {
        path: '/pai',
        name: 'pai',
        component: pai,
    }, {
        path: '/this_pai',
        name: 'this_pai',
        component: this_pai,
    }, {
        path: '/product',
        name: 'product',
        component: product,
    }, {
        path: '/show',
        name: 'show',
        component: show,
    }, {
        path: '/detail',
        name: 'detail',
        component: detail,
    },
    {
        path: '/Sale',
        name: 'Sale',
        component: Sale,
    },

    {
        path: '/vip',
        name: 'vip',
        component: epai_vip,
    },
    {
        path: '/myvip',
        name: 'myvip',
        component: myvip,
    },
    {
        path: '/vips',
        name: 'vips',
        component: vips,
    },
    {
        path: '/idnum',
        name: 'idnum',
        component: idnum,
    },
    {
        path: '/login',
        name: 'login',
        component: login,
    },
    {
        path: '/index',
        name: 'index',
        component: index,
    },
    {
        path: '/register',
        name: 'register',
        component: register,
    },
    {
        path: '/myvip_leave',
        name: 'myvip_leave',
        component: myvip_leave,
    },
    {
        path: '/money',
        name: 'money',
        component: money,
    },

    {
        path: '/order',
        component: Order,
        children: [{
                path: 'allOrder',
                component: AllOrder
            },
            {
                path: 'successFulOrder',
                component: SuccessFulOrder
            },
            {
                path: 'failedOrder',
                component: FailedOrder
            }, {
                path: 'unpaidOrder',
                component: UnpaidOrder
            }



        ]
    }


]



const router = new VueRouter({
    mode: "history",
    routes
})

//全局路由前置守卫
router.beforeEach((to, from, next) => {
    console.log(to);
    if (to.path == '/login') {
        next();
    } else if (to.path == '/') {
        next();
    } else if (to.path == '/show') {
        next();
    } else if (to.path == '/register') {
        next();
    } else {
        //记载时，若没有登录，则跳转回登录页
        if (!sessionStorage.getItem("uid")) {
            alert("未登录请先登录");
            router.push("/login");
        } else {
            next();
        }
    }
})

export default router